package cn.schoolwow.workflow.module.definition.action.kit;

import cn.schoolwow.workflow.domain.deploy.WorkFlowDefinitionOption;
import cn.schoolwow.workflow.domain.deploy.WorkFlowDeployRequest;
import cn.schoolwow.workflow.module.common.domain.QuickWorkFlowConfig;
import cn.schoolwow.workflow.module.definition.action.service.DeleteWorkFlowDefinitionServiceFlow;
import cn.schoolwow.workflow.module.definition.action.service.DeployWorkFlowServiceFlow;
import cn.schoolwow.workflow.module.definition.action.service.UpdateWorkFlowDeployOptionServiceFlow;

public class WorkFlowDeployActionImpl implements WorkFlowDeployAction {
    private QuickWorkFlowConfig quickWorkFlowConfig;

    public WorkFlowDeployActionImpl(QuickWorkFlowConfig quickWorkFlowConfig) {
        this.quickWorkFlowConfig = quickWorkFlowConfig;
    }

    @Override
    public void deployWorkFlow(WorkFlowDeployRequest workFlowDeployRequest) {
        quickWorkFlowConfig.workflow.startFlow(new DeployWorkFlowServiceFlow())
                .putTemporaryInstanceData(workFlowDeployRequest)
                .execute();
    }

    @Override
    public void deleteWorkFlowDefinition(String name) {
        quickWorkFlowConfig.workflow.startFlow(new DeleteWorkFlowDefinitionServiceFlow())
                .putTemporaryData("name", name)
                .execute();
    }

    @Override
    public void updateWorkFlowDefinitionOption(String name, WorkFlowDefinitionOption workFlowDefinitionOption) {
        quickWorkFlowConfig.workflow.startFlow(new UpdateWorkFlowDeployOptionServiceFlow())
                .putData("name", name)
                .putInstanceData(workFlowDefinitionOption)
                .execute();
    }

}
